import request from "@/utils/request"
import type { spuInfoModel } from "@/api/product/model/spu"
enum Api {
  // 获取spu列表的API
  getSpuListApi = "/admin/product",
  // 添加SPU的API
  saveSpuInfoApi = "/admin/product/saveSpuInfo",
  // 更新SPU的API
  updateSpuInfoApi = "/admin/product/updateSpuInfo",
  // 删除SPU的API
  deleteSpuInfoApi = "/admin/product/deleteSpu",
  // 获取所有的属性数据
  GetBaseSaleAttrList = "/admin/product/baseSaleAttrList",
  // 添加SPU的API
  SaveSpu = "/admin/product/saveSpuInfo",
  // 更新SPU的API
  UpdateSpu = "/admin/product/updateSpuInfo",
  // 获取销售属性列表
  GetSpuSaleAttrList = "/admin/product/spuSaleAttrList",
  // 获取图片列表
  GetSpuImageList = "/admin/product/spuImageList",
  // 获取spu详情
  GetSpuInfo = "/admin/product/getSpuById",
  // 获取所有trademark数据
  getTrademarkApi = "/admin/product/baseTrademark/getTrademarkList",
}

// 获取spu列表
export const reqGetSpuListData = ({
  currentPage,
  pageSize,
  category3Id,
}: any) => {
  return request.get<any, any>(
    Api.getSpuListApi + `/${currentPage}/${pageSize}`,
    {
      params: {
        category3Id,
      },
    }
  )
}

// 添加Spu
/* 
{
  "category3Id": 0,
  "createTime": "2022-08-15T02:48:42.697Z",
  "description": "string",
  "id": 0,
  "spuImageList": [
    {
      "createTime": "2022-08-15T02:48:42.697Z",
      "id": 0,
      "imgName": "string",
      "imgUrl": "string",
      "spuId": 0,
      "updateTime": "2022-08-15T02:48:42.697Z"
    }
  ],
  "spuName": "string",
  "spuPosterList": [
    {
      "createTime": "2022-08-15T02:48:42.697Z",
      "id": 0,
      "imgName": "string",
      "imgUrl": "string",
      "spuId": 0,
      "updateTime": "2022-08-15T02:48:42.697Z"
    }
  ],
  "spuSaleAttrList": [
    {
      "baseSaleAttrId": 0,
      "createTime": "2022-08-15T02:48:42.697Z",
      "id": 0,
      "saleAttrName": "string",
      "spuId": 0,
      "spuSaleAttrValueList": [
        {
          "baseSaleAttrId": 0,
          "createTime": "2022-08-15T02:48:42.697Z",
          "id": 0,
          "isChecked": "string",
          "saleAttrName": "string",
          "saleAttrValueName": "string",
          "spuId": 0,
          "updateTime": "2022-08-15T02:48:42.697Z"
        }
      ],
      "updateTime": "2022-08-15T02:48:42.697Z"
    }
  ],
  "tmId": 0,
  "updateTime": "2022-08-15T02:48:42.697Z"
}

*/
export const reqSaveSpuInfo = (spuInfo: spuInfoModel) => {
  return request.post<any, any>(Api.saveSpuInfoApi, spuInfo)
}

// 更新Spu
export const reqUpdateSpuInfo = (spuInfo: spuInfoModel) => {
  return request.post<any, any>(Api.updateSpuInfoApi, spuInfo)
}

// 删除
export const reqDeleteSpuInfo = (spuId: number) => {
  return request.delete(Api.deleteSpuInfoApi + `/${spuId}`)
}

// 获取spu页面所有的属性数据
export const reqGetSpuBaseList = () => {
  return request.get<any, any>(Api.GetBaseSaleAttrList)
}
// 获取所有trademark数据
export const reqGetTrademarkList = () => {
  return request.get<any, any>(Api.getTrademarkApi)
}

// 修改获取销售属性列表
export const getSpuSaleAttrListApi = (spuId: number) => {
  return request.get<any, any>(Api.GetSpuSaleAttrList + `/${spuId}`)
}

// 获取spu详情
export const getSpuInfoData = (spuId: number) => {
  return request.get<any, any>(Api.GetSpuInfo + `/${spuId}`)
}

// 获取图片列表
export const reqGetSpuImageList = (spuId: number) => {
  return request.get<any, any>(Api.GetSpuImageList + `/${spuId}`)
}

// 获取销售属性列表
export const reqGetSpuSaleAttrList = (spuId: number) => {
  return request.get<any, any>(Api.GetSpuSaleAttrList + `/${spuId}`)
}
